<template>
  <view class="container">
    <!-- 固定的顶部区域 -->
    <view class="fixed-top">
      <status-bar bgColor="#0088ff"></status-bar>
      <!-- 顶部标题栏 -->
      <view class="nav-bar">
        <view class="back-btn" @click="goBack">
          <image src="/static/images/icon/backward_flat.png" class="back-icon-img"></image>
        </view>
        <view class="nav-title">选择产品名称</view>
      </view>
    </view>

    <!-- 可滚动的内容区域 -->
    <scroll-view class="content" scroll-y="true">
      <!-- 列表区域 -->
      <uni-list>
        <uni-list-item 
          v-for="(item, index) in productOptions" 
          :key="index"
          :title="item.name"
          @click.native="selectItem(item)"
          hover-class="list-item-hover"
          style="pointer-events: auto;"
        >
          <template v-slot:footer>
            <view class="radio-container">
              <view :class="['radio-icon', selectedValue === item.value ? 'selected' : '']">
                <view v-if="selectedValue === item.value" class="radio-inner"></view>
              </view>
            </view>
          </template>
        </uni-list-item>
      </uni-list>
    </scroll-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      selectedValue: '',
      productOptions: [
        { value: 'straight_track', name: '直轨' },
        { value: 'ultra_thin_straight_track', name: '超薄直轨' },
        { value: 'bend_track', name: '弯轨' },
        { value: 'ultra_thin_bend_track', name: '超薄弯轨' },
        { value: 'roman_pole', name: '罗马杆' },
        { value: 'dream_curtain', name: '梦幻帘' },
        { value: 'shutter', name: '百叶帘' },
        { value: 'roll_curtain', name: '卷帘' },
        { value: 'shangri_la_curtain', name: '香格里拉帘' },
        { value: 'zebra_blind', name: '柔纱帘/斑马帘' }
      ]
    }
  },
  methods: {
    goBack() {
      uni.navigateBack();
    },
    selectItem(item) {
      console.log('选择的产品:', item); // 调试日志
      this.selectedValue = item.value;
      
      // 直接发送事件并返回
      uni.$emit('SELECT_PRODUCT_NAME', item);
      uni.navigateBack({ delta: 1 });
      
      // 强制刷新UI
      this.$forceUpdate();
    }
  }
}
</script>

<style>
.container {
  background-color: #f5f5f5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* 固定顶部区域 */
.fixed-top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

/* 顶部导航栏 */
.nav-bar {
  display: flex;
  align-items: center;
  height: 90rpx;
  background-color: #0088ff;
  color: #fff;
  padding: 0 30rpx;
  position: relative;
}

.back-btn {
  position: absolute;
  left: 30rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-icon-img {
  width: 40rpx;
  height: 40rpx;
}

.nav-title {
  flex: 1;
  text-align: center;
  font-size: 36rpx;
  font-weight: bold;
}

/* 内容区域 */
.content {
  margin-top: 140rpx; /* 状态栏+导航栏高度 */
}

/* 列表项悬停效果 */
.list-item-hover {
  background-color: #f0f0f0;
}

/* 单选按钮样式 */
.radio-container {
  display: flex;
  align-items: center;
}

.radio-icon {
  width: 30rpx;
  height: 30rpx;
  border: 2rpx solid #999;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.radio-icon.selected {
  border-color: #0088ff;
}

.radio-inner {
  width: 24rpx;
  height: 24rpx;
  background-color: #0088ff;
  border-radius: 50%;
}
</style>